package com.caikun.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.caikun.entity.Userinfos;
import com.caikun.services.UserinfosService;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Servlet implementation class upnameController
 */
public class upnameController extends HttpServlet {
	private static final long serialVersionUID = 1L;    
	private UserinfosService us = new UserinfosService();

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		Object bind = request.getSession().getAttribute("bind");
		if(bind != null){
			String nickname =request.getParameter("nickname");
			System.out.println(nickname);
			PrintWriter out =response.getWriter();
			int result = us.modifyNickname(nickname, bind.toString());
			if(result>0){
				out.write("{\"status\":\"666\",\"bind\":\""+bind+"\"}");	
			}else{
				out.write("{\"status\":\"444\"}");
			}
		}
	}
}

